package hn.cch.grammar.gc;

import java.util.ArrayList;
import java.util.List;

/**
 * 内存溢出用例:Java heap space
 */
public class OutOfMemoryDemo {

    // 1MB = 1024KB = 1024 * 1024 B
    public byte[] data = new byte[1024 * 1024];

    /**
     * -Xms10m -Xmx10m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath="hdoom.hprof"
     *
     * @param args
     */
    public static void main(String[] args) {

        List<OutOfMemoryDemo> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(new OutOfMemoryDemo());
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                System.out.println(e.getMessage());
            }
        }
    }
}


